﻿// 版权归百小僧及百签科技（广东）有限公司所有。
//
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证。

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// 手动注册ApiController
    /// </summary>
    public static class ManualRegisterDynamicApiControllerExtensions
    {
        private static List<Type> manualApiControllers = new List<Type>();
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IReadOnlyList<Type> GetManualApiControllers() { return manualApiControllers.AsReadOnly(); }
        /// <summary>
        /// 添加动态接口
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddRestController<T>(this IServiceCollection services)
        {
            manualApiControllers.Add(typeof(T));
            return services;
        }
        /// <summary>
        /// 添加动态接口
        /// </summary>
        /// <param name="services"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public static IServiceCollection AddRestControllers(this IServiceCollection services, params Type[] types)
        {
            manualApiControllers.AddRange(types);
            return services;
        }
        /// <summary>
        /// 添加动态接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static void AddRestControllers<T>()
        {
            manualApiControllers.Add(typeof(T));
        }
        /// <summary>
        /// 添加动态接口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static void AddRestControllers(params Type[] types)
        {
            manualApiControllers.AddRange(types);
        }
    }
}
